#ifndef _SERVER_H
#define _SERVER_H

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0601	// required by `getaddrinfo`
#include <ws2tcpip.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define BUFSIZE 8192

bool InitSocket();
std::string NormalPath(std::string);
class Address {
	public:
		Address();
		Address(std::string);
		Address(std::string,int);
		Address(sockaddr *);
		Address(Address *);
		std::string ToString();
		bool FromHost(std::string,int);
		bool FromHost(std::string);
		bool FromHost();
		bool FromSockAddr(sockaddr *);
		bool FromSockAddr();
		sockaddr SockAddress();
	private:
		std::string host;
		int port;
		union ADDR_EX {	// enhanced sockaddr
			struct sockaddr addr;
			struct sockaddr_in addrv4;
			struct sockaddr_in6 addrv6;
		} addrex;
		int GetType();
};
class Server {
	public:
		Server();
		void SetAddress(Address *);
		bool Bind();
		virtual void StartServer();
	protected:
		SOCKET sock;
		Address *addr;
		int status;
};

#endif
